import axiosInstance from '../request'

/**
 * 登录接口
 */
export const RequestLogin = (username, password) => {
    return axiosInstance({
        method: 'post',
        url: '/api/login',
        data: {
            username,
            password,
        },
    })
}

/**
 * 商品列表接口
 */
export const RequestGoodsList = (pageNo = 1, pageSize = 5) => {
    return axiosInstance({
        method: 'get',
        url: '/api/shop',
        params: {
            pageNo,
            pageSize,
        },
    })
}

/**
 * 商品分类列表
 */
export const RequestCategorys = () => {
    return axiosInstance({
        method: 'get',
        url: '/api/category',
    })
}

/**
 * 上传商品
 *   上传图片文件 post
 *   如果上传小图片，将小图片base64,拼接到url地址上一起上传
 *    content-type:
 *    FormData 表单对象
 */
export const RequestGoodsAdd = formData => {
    return axiosInstance({
        method: 'post',
        url: '/api/shop/insert',
        headers: { 'Content-Type': 'multipart/form-data'},
        data: formData,
    })
}

/**
 * 编辑商品
 */
export const RequestGoodsEdit = formData => {
    return axiosInstance({
        method: 'post',
        url: '/api/shop/edit',
        headers: { 'Content-Type': 'multipart/form-data' },
        data: formData,
    })
}


/**
 * 删除商品
 */
export const RequestGoodDelete = id => {
    // const token = localStorage.getItem('TOKEN')
    return axiosInstance({
        method: 'get',
        url: '/api/shop/delete',
        headers: { 'Content-Type': 'multipart/form-data' },
        // headers: { 'Content-Type': 'multipart/form-data', Authorization: token },
        params: {
            id,
        },
    })
}
